
/**
 * Created by Administrator on 2018/7/27/027.
 */
// layui方法

layui.use(['table', 'form', 'layer','vip_table','laydate'], function () {

    // 操作对象
    var form = layui.form
        , table = layui.table
        , layer = layui.layer
        , vipTable = layui.vip_table
        , laydate = layui.laydate
        , $ = layui.jquery;



    var token = $('#_token').val();
    var tableIns;
    //初始化
    getReOrderList();

    //绑定日期插件
    laydate.render({
        elem: '#start_date', //指定元素
    });
    laydate.render({
        elem: '#end_date', //指定元素
    });
    //清空
    $('.clear').on('click', function () {
        location.href='/rechargeOrder'
    });

    //查询
    form.on('submit(search)', function (data) {
        var search_data = data.field;
        getReOrderList(search_data);
    });

    //导出
    form.on('submit(download)', function (data) {
        layer.confirm('默认导出5000条数据，是否导出', {
            btn: ['确定','取消'] //按钮
        }, function(){
            var search_data = data.field;
            layer.closeAll();
            var url ='/downReOrderList?page=1&limit=5000'+'&mobile='+search_data.mobile+'&order_no='+search_data.order_no
                +'&start_date='+search_data.start_date+'&end_date='+search_data.end_date+'&set_meal_type='+search_data.set_meal_type;
            window.open(url,'_blank');
        })

    });

    // 列表
    function getReOrderList(data) {
        tableIns = table.render({
            elem: '#re_order_data',
            // height: vipTable.getFullHeight(),    //容器高度
            page: true,
            count: 100,
            limit: 10,
            cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            layout: ['count', 'prev', 'page', 'next', 'limit', 'skip'],
            jump: function(obj){
                //console.log(obj)
            },
            cols: [[                  //标题栏
                {field: 'order_no', title: '订单号'}
                , {field: 'mobile', title: '会员手机号'}
                , {field: 'money', title: '充值金额'}
                , {field: 'actual_account', title: '实际到账金额'}
                , {field: 'payment_channel', title: '支付类型'}
                , {field: 'recharge_type_name', title: '充值类型'}
                , {field: 'order_original_name', title: '订单来源'}
                , {field: 'created_at', title: '创建时间'}

            ]],
            url: '/getReOrderList',
            where: data,
            method: 'get',
            done: function (res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                // console.log(res);

                //得到当前页码
                // console.log(curr);

                //得到数据总量
                // console.log(count);
            }
        });
    }


});